package top.wettis.chat.controller;


import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.wettis.chat.constant.ResultType;
import top.wettis.chat.pojo.DO.Objectives;
import top.wettis.chat.pojo.VO.Result;
import top.wettis.chat.service.IObjectivesService;
import top.wettis.chat.service.ITaskService;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/plan")
public class PlanController {
    @Autowired
    public ITaskService iTaskService;

    @Autowired
    public IObjectivesService iObjectivesService;

    @PostMapping("/delete")
    public Result<Object> delete(){

        int userid = StpUtil.getLoginIdAsInt();;
        iTaskService.deleteAll(userid);
        iObjectivesService.deleteAll(userid);
        return Result.successInfo(ResultType.DELETE ,"删除成功");
    }

    @GetMapping("/getAllPlansCount")
    public Integer getAllPlans(){
        int userid = StpUtil.getLoginIdAsInt();
        return iObjectivesService.countsall(userid);
    }

    @GetMapping("/getStatePlan")
    public HashMap<String, Object> getStatePlan(){
        int userid = StpUtil.getLoginIdAsInt();
        return iTaskService.getStatePlan(userid);
    }

    @GetMapping("/TodayPlan")
    public String TodayPlan(){
        int userid = StpUtil.getLoginIdAsInt();
        Objectives objectives = iObjectivesService.selectCurPlan(userid);
        return objectives.getContent();
    }
}
